package questionSolution.Question_198;

public class Solution_1 {
    public int rob(int[] nums) {
        int[] dp = new int[nums.length+1];
        int res = 0;
        dp[0] = 0;
        dp[1] = nums[0];
        for (int i = 2; i<= nums.length; i++){
            dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i - 1]);
        }
        res = Math.max(dp[nums.length], res);
        return res;
    }

    static void main() {
        Solution_1 sol = new Solution_1();
        int[]  nums = {2,7,9,3,1, 8, 6, 7};
        int res = sol.rob(nums);
        System.out.println(res);
    }
}
